home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / Apple Game Sprockets / Examples / InputSprocketPPTest / ISpEventPane.cp < prev    next >
Encoding:
Text File  |  1996-05-16  |  2.8 KB  |  130 lines  |  [TEXT/CWIE]

  1. //====
  2. // ISpEventPane.cp
  3. //=====
  4.  
  5. #include "ISpEventPane.h"
  6. #include "ISpTestGlobals.h"
  7. #include <TextUtils.h>
  8. #include "ISpPPTestTools.h"
  9.  
  10. ISpEventPane::ISpEventPane(LStream *inStream):LOffscreenView(inStream)
  11. {
  12.     mDataValid = false;
  13.     StartIdling();
  14. }
  15.  
  16. ISpEventPane::~ISpEventPane()
  17. {
  18. }
  19.  
  20. ISpEventPane *ISpEventPane::CreateISpEventPaneStream(LStream *inStream)
  21. {
  22.   return (new ISpEventPane(inStream));
  23. }
  24.  
  25.  
  26. void ISpEventPane::SpendTime(const EventRecord &inMacEvent)
  27. {
  28.     
  29.     if (gElementList == nil) { return; }
  30.  
  31.     ISpElementEvent theEvent;
  32.     
  33.     OSStatus theErr;
  34.     Boolean wasEvent;
  35.     
  36.     theErr = ISpElementList_GetNextEvent(    gElementList, 
  37.                                             sizeof(ISpElementEvent),
  38.                                             &theEvent,
  39.                                             &wasEvent);
  40.     
  41.     if (wasEvent)
  42.     {
  43.         mDataValid = true;
  44.         
  45.         mPrintRecord.theError = theErr;        
  46.         mPrintRecord.when = theEvent.when;
  47.         mPrintRecord.data = theEvent.data;
  48.         mPrintRecord.theElement = theEvent.element;
  49.         mPrintRecord.refCon = theEvent.refCon;
  50.         mPrintRecord.percent = theEvent.data;
  51.         float max = 0xffffffff;
  52.         mPrintRecord.percent /= max;
  53.         
  54.         ISpElementInfo info;
  55.         ISpElement_GetInfo(theEvent.element, &info);
  56.         mPrintRecord.label = info.theLabel;
  57.         mPrintRecord.kind = info.theKind;
  58.         BlockMoveData(info.theString, mPrintRecord.theString, 64);
  59.         Refresh();
  60.         UpdatePort();
  61.     }
  62. }
  63.  
  64.  
  65.  
  66. void ISpEventPane::DrawSelf()
  67. {
  68.     if (!mDataValid) { return; }
  69.     
  70.     Rect r;
  71.     Str255 theString;
  72.         
  73.     CalcLocalFrameRect(r);
  74.     r.left += 10;
  75.     EraseRect(&r);
  76.  
  77.     MoveTo(r.left, r.top + 15);
  78.     DrawString("\pError Code:  ");
  79.     NumToString(mPrintRecord.theError, theString);
  80.     DrawString(theString);
  81.  
  82.     MoveTo(r.left, r.top + 30);
  83.     DrawString("\pTime:  ");
  84.     UnsignedWideToHexString(mPrintRecord.when, theString);
  85.     DrawString(theString);
  86.  
  87.     MoveTo(r.left, r.top + 45);
  88.     DrawString("\pData:  ");
  89.     UInt32ToHexString(mPrintRecord.data, theString);
  90.     DrawString(theString);
  91.     
  92.     {
  93.         const rectWidth = 100;
  94.         Rect maxRect = {2,0,11,rectWidth};
  95.         Rect progRect = maxRect;
  96.         
  97.         progRect.right = rectWidth * mPrintRecord.percent;
  98.         
  99.         OffsetRect(&maxRect, r.left, r.top + 47);
  100.         OffsetRect(&progRect, r.left, r.top + 47);
  101.         
  102.         ::FrameRect(&maxRect);
  103.         ::PaintRect(&progRect);
  104.     }
  105.  
  106.     MoveTo(r.left, r.top + 75);
  107.     DrawString("\pElement Num:  ");
  108.     UInt32ToHexString((unsigned long) mPrintRecord.theElement, theString);
  109.     DrawString(theString);
  110.  
  111.     MoveTo(r.left, r.top + 90);
  112.     DrawString("\prefCon:  ");
  113.     UInt32ToHexString(mPrintRecord.refCon, theString);
  114.     DrawString(theString);
  115.  
  116.     MoveTo(r.left, r.top + 105);
  117.     DrawString("\pElement Label:  ");
  118.     UInt32ToFourByte(mPrintRecord.label, theString);
  119.     DrawString(theString);
  120.  
  121.     MoveTo(r.left, r.top + 120);
  122.     DrawString("\pElement Kind:  ");
  123.     UInt32ToFourByte(mPrintRecord.kind, theString);
  124.     DrawString(theString);
  125.  
  126.     MoveTo(r.left, r.top + 135);
  127.     DrawString("\pElement Name:  ");
  128.     DrawString(mPrintRecord.theString);
  129.  
  130. }